<template>
  <div class="app-container calendar-list-container" id="msg" >
    <el-table :data="msg"
              v-loading.fullscreen="isLoading"
              element-loading-background="rgba(0, 0, 0, 0.6)"
              border
              fit
              highlight-current-row
              style="width: 100%"
    >
      <el-table-column align="center" label="留言时间" min-width="110px">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span>{{scope.row.time | parseTime('{y}-{m}-{d} {h}:{i}')}}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="60px" label="姓名">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="80px" label="手机">
        <template slot-scope="scope">
          <span>{{ scope.row.phone }}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="110px" label="邮箱">
        <template slot-scope="scope">
          <span>{{ scope.row.email }}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="150px" label="标题">
        <template slot-scope="scope">
          <span>{{ scope.row.tittle }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="操作" width="160">
        <template slot-scope="scope">
          <el-button type="success" v-waves @click='handleCheck(scope.row)' size="small" >详情</el-button>
          <el-button type="danger" v-waves @click='handleDelete(scope.row)' size="small" >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <check-dialog :checkTemp="checkTemp"
                  :dialogCheckVisible="dialogCheckVisible"
                  @close="handleCloseCheck"
    ></check-dialog>

  </div>
</template>

<script>
  import { getMsg, deleteMsg } from '@/api/msg'
  import { parseTime } from '@/utils'
  import waves from '@/directive/waves/index.js'
  import CheckDialog from './components/CheckDialog'

  export default {
    data() {
      return {
        msg: null,
        isLoading: false,
        deleteTemp: {},
        checkTemp: {},
        dialogCheckVisible: false,
        admin_id: null,
        token: null
      }
    },
    components: {
      CheckDialog
    },
    directives: {
      waves
    },
    filters: {
      parseTime
    },
    created() {
      this.admin_id = this.$store.state.user.admin_id
      this.token = this.$store.state.user.token
      this.getMsg()
    },
    methods: {
      getMsg() {
        this.listLoading = true
        getMsg(this.admin_id, this.token).then(res => {
          // console.log(res)
          const items = res.data
          this.msg = items
          this.isLoading = false
        })
      },
      handleCheck(row) {
        this.checkTemp = Object.assign({}, row) // copy obj
        this.dialogCheckVisible = true
      },
      handleCloseCheck(boolean) {
        this.checkTemp = {}
        this.dialogCheckVisible = boolean
      },
      handleDelete(row) {
        this.$confirm('此操作将永久删除该职位, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.deleteTemp = Object.assign({}, row)
          this.isLoading = true
          deleteMsg(this.admin_id, this.token, this.deleteTemp.id).then(res => {
            this.isLoading = false
            this.dialogUpdateFormVisible = false
            this.$notify({
              title: '成功',
              message: '删除成功',
              type: 'success',
              duration: 2000
            })
            this.getMsg()
          })
        }).catch(() => {
          this.$notify({
            title: '取消',
            message: '已取消删除',
            type: 'info',
            duration: 2000
          })
        })
      }
    }
  }
</script>

<style scoped>
  .edit-input {
    padding-right: 100px;
  }
  .cancel-btn {
    position: absolute;
    right: 15px;
    top: 10px;
  }

</style>
